package mafiagame;

public class VoteAction extends Action
{
	Game myGame;
	Player myPlayer;
	public VoteAction(Game g, Player p)
	{
		myGame = g;
		myPlayer = p;
	}
	
	@Override
	public String getDescription()
	{
		return "You must vote for a player to execute. The format is 'execute [number]' where the number corresponds to the player you wish to kill. Remember you can ask god privately for a 'list'";
	}

	@Override
	public String getCommand()
	{
		return "execute";
	}

	@Override
	public boolean Execute(String message)
	{
		String[] tokens = message.split(" ");
		if (tokens.length != 2)
		{
			myGame.communicator.sendPrivateMessage(myPlayer.username, "The exeuctions must be of the format 'execute [number]' where the number is the player number you wish to kill.");
			return false;
		}
		Player p = myGame.parsePlayer(tokens[1]); 
		if (p == null)
		{
			myGame.communicator.sendPrivateMessage(myPlayer.username, "You must choose a player who is actually playing.");
			return false;
		}
		if (!p.living)
		{
			myGame.communicator.sendPrivateMessage(myPlayer.username, "You must choose a player who is alive to kill.");
			return false;
		}
		
		myGame.communicator.sendPrivateMessage(myPlayer.username, "You have voted to execute <b>" + p.username + "</b>. You may cancel it by saying 'unvote'");
		myPlayer.playerVote = p.id;
		
		myGame.addAction(myPlayer.username, new UnvoteExecutionAction(myGame, myPlayer), false);
		
		myGame.tryEndDay();
		
		return true;
	}

	@Override
	public boolean isPublic()
	{
		return true;
	}

	@Override
	public void Resolve()
	{
		// This action should never actually be resolved.		
	}

}
